﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IrisGenerator.Common.DatabaseModel;

namespace IrisGenerator.Modules.SqlServer2005.Rules
{
    internal static class SpGenerationRules
    {
        internal static bool CanGenerateSelectAll(Table table)
        {
            return true;
        }

        internal static bool CanGenerateSelectFromPrimaryKey(Table table)
        {
            
            if (table == null || 
                table.ColumnCollection.Count.Equals(0) || 
                table.Constraints.Count.Equals(0))
                return false;

            if (table.Constraints.ConstraintTypeExists(ConstraintType.PRIMARY_KEY))
                return true;
            return false;
        }

        internal static bool CanGenerateSelectFromForeignKey(Table table)
        {
            if (table == null ||
                table.ColumnCollection.Count.Equals(0) ||
                table.Constraints.Count.Equals(0))
                return false;

            if (table.Constraints.ConstraintTypeExists(ConstraintType.FOREIGN_KEY))
                return true;
            return false;
        }

        internal static bool CanGenerateUpdate(Table table)
        {
            return (CanGenerateSelectFromPrimaryKey(table));
        }

        internal static bool CanGenerateDelete(Table table)
        {
            return (CanGenerateSelectFromPrimaryKey(table));
        }

        internal static bool CanGenerateInsert(Table table)
        {
            return true;
        }
    }
}
